package com.ecommerceWeb.common;

import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.context.support.WebApplicationContextUtils;




public class ServiceFinder implements
ApplicationContextAware {

	private ApplicationContext applicationContext;

	public static Object findBean(String beanName){
		
		
		FacesContext context= FacesContext.getCurrentInstance();

		ServletContext servletContext = 
		    (ServletContext)context.getExternalContext().getContext();
		ApplicationContext appContext =
		    WebApplicationContextUtils.getWebApplicationContext(servletContext);

		Object o =appContext.getBean(beanName);
		
		return o ;

	}
	public Object getMyBean(String beanName)
	{
		return getApplicationContext().getAliases(beanName);
	}

	public ApplicationContext getApplicationContext() {
		return applicationContext;
	}
	public void setApplicationContext(ApplicationContext arg0)
			throws BeansException {
		// TODO Auto-generated method stub
		this.applicationContext=arg0;
		
	}

 } 
